import {
    DimensionType,
    FieldType,
    MetricType,
    SupportedDbtAdapter,
    type Explore,
} from '@lightdash/common';

/**
 * Comprehensive mock Explore for validation tests.
 * Includes orders table (used by most tests) and users table (for multi-table tests).
 */
export const mockOrdersExplore: Explore = {
    targetDatabase: SupportedDbtAdapter.POSTGRES,
    name: 'test_explore',
    label: 'Test Explore',
    tags: [],
    spotlight: {
        visibility: 'show',
        categories: [],
    },
    baseTable: 'orders',
    joinedTables: [],
    tables: {
        orders: {
            name: 'orders',
            label: 'Orders',
            database: 'test_db',
            schema: 'public',
            sqlTable: 'orders',
            sqlWhere: undefined,
            uncompiledSqlWhere: undefined,
            dimensions: {
                order_id: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.NUMBER,
                    name: 'order_id',
                    label: 'Order ID',
                    table: 'orders',
                    tableLabel: 'Orders',
                    sql: '${TABLE}.order_id',
                    hidden: false,
                    source: undefined,
                    compiledSql: 'orders.order_id',
                    tablesReferences: ['orders'],
                },
                order_date: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.DATE,
                    name: 'order_date',
                    label: 'Order Date',
                    table: 'orders',
                    tableLabel: 'Orders',
                    sql: '${TABLE}.order_date',
                    hidden: false,
                    source: undefined,
                    compiledSql: 'orders.order_date',
                    tablesReferences: ['orders'],
                },
                customer_name: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'customer_name',
                    label: 'Customer Name',
                    table: 'orders',
                    tableLabel: 'Orders',
                    sql: '${TABLE}.customer_name',
                    hidden: false,
                    source: undefined,
                    compiledSql: 'orders.customer_name',
                    tablesReferences: ['orders'],
                },
                product_category: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'product_category',
                    label: 'Product Category',
                    table: 'orders',
                    tableLabel: 'Orders',
                    sql: '${TABLE}.product_category',
                    hidden: false,
                    source: undefined,
                    compiledSql: 'orders.product_category',
                    tablesReferences: ['orders'],
                },
                amount: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.NUMBER,
                    name: 'amount',
                    label: 'Amount',
                    table: 'orders',
                    tableLabel: 'Orders',
                    sql: '${TABLE}.amount',
                    hidden: false,
                    source: undefined,
                    compiledSql: 'orders.amount',
                    tablesReferences: ['orders'],
                },
                is_active: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.BOOLEAN,
                    name: 'is_active',
                    label: 'Is Active',
                    table: 'orders',
                    tableLabel: 'Orders',
                    sql: '${TABLE}.is_active',
                    hidden: false,
                    source: undefined,
                    compiledSql: 'orders.is_active',
                    tablesReferences: ['orders'],
                },
            },
            metrics: {
                total_revenue: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.SUM,
                    name: 'total_revenue',
                    label: 'Total Revenue',
                    table: 'orders',
                    tableLabel: 'Orders',
                    sql: 'SUM(${TABLE}.amount)',
                    hidden: false,
                    source: undefined,
                    compiledSql: 'SUM(orders.amount)',
                    tablesReferences: ['orders'],
                },
                order_count: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.COUNT,
                    name: 'order_count',
                    label: 'Order Count',
                    table: 'orders',
                    tableLabel: 'Orders',
                    sql: 'COUNT(*)',
                    hidden: false,
                    source: undefined,
                    compiledSql: 'COUNT(*)',
                    tablesReferences: ['orders'],
                },
                avg_order_value: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.AVERAGE,
                    name: 'avg_order_value',
                    label: 'Average Order Value',
                    table: 'orders',
                    tableLabel: 'Orders',
                    sql: 'AVG(${TABLE}.amount)',
                    hidden: false,
                    source: undefined,
                    compiledSql: 'AVG(orders.amount)',
                    tablesReferences: ['orders'],
                },
                max_date: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.MAX,
                    name: 'max_date',
                    label: 'Max Date',
                    table: 'orders',
                    tableLabel: 'Orders',
                    sql: 'MAX(${TABLE}.created_at)',
                    hidden: false,
                    source: undefined,
                    compiledSql: 'MAX(orders.created_at)',
                    tablesReferences: ['orders'],
                },
            },
            lineageGraph: {},
            source: undefined,
            groupLabel: undefined,
        },
    },
    groupLabel: undefined,
    warehouse: undefined,
    sqlPath: undefined,
    ymlPath: undefined,
    databricksCompute: undefined,
};

/**
 * Mock Explore with joined tables for multi-table validation tests.
 * Base table is users, with orders as a joined table.
 */
export const mockUsersOrdersExplore: Explore = {
    targetDatabase: SupportedDbtAdapter.POSTGRES,
    name: 'test_explore',
    label: 'Test Explore',
    tags: [],
    spotlight: {
        visibility: 'show',
        categories: [],
    },
    baseTable: 'users',
    joinedTables: [
        {
            table: 'orders',
            sqlOn: '${users.user_id} = ${orders.user_id}',
            compiledSqlOn: '(users.user_id) = (orders.user_id)',
            type: undefined,
        },
    ],
    tables: {
        users: {
            name: 'users',
            label: 'Users',
            database: 'test_db',
            schema: 'public',
            sqlTable: 'users',
            sqlWhere: undefined,
            uncompiledSqlWhere: undefined,
            dimensions: {
                user_id: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.NUMBER,
                    name: 'user_id',
                    label: 'User ID',
                    table: 'users',
                    tableLabel: 'Users',
                    sql: '${TABLE}.user_id',
                    hidden: false,
                    source: undefined,
                    compiledSql: 'users.user_id',
                    tablesReferences: ['users'],
                },
                user_name: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'user_name',
                    label: 'User Name',
                    table: 'users',
                    tableLabel: 'Users',
                    sql: '${TABLE}.user_name',
                    hidden: false,
                    source: undefined,
                    compiledSql: 'users.user_name',
                    tablesReferences: ['users'],
                },
            },
            metrics: {
                total_users: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.COUNT,
                    name: 'total_users',
                    label: 'Total Users',
                    table: 'users',
                    tableLabel: 'Users',
                    sql: 'COUNT(*)',
                    hidden: false,
                    source: undefined,
                    compiledSql: 'COUNT(*)',
                    tablesReferences: ['users'],
                },
            },
            lineageGraph: {},
            source: undefined,
            groupLabel: undefined,
        },
        orders: {
            name: 'orders',
            label: 'Orders',
            database: 'test_db',
            schema: 'public',
            sqlTable: 'orders',
            sqlWhere: undefined,
            uncompiledSqlWhere: undefined,
            dimensions: {
                order_id: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.NUMBER,
                    name: 'order_id',
                    label: 'Order ID',
                    table: 'orders',
                    tableLabel: 'Orders',
                    sql: '${TABLE}.order_id',
                    hidden: false,
                    source: undefined,
                    compiledSql: 'orders.order_id',
                    tablesReferences: ['orders'],
                },
            },
            metrics: {},
            lineageGraph: {},
            source: undefined,
            groupLabel: undefined,
        },
    },
    groupLabel: undefined,
    warehouse: undefined,
    sqlPath: undefined,
    ymlPath: undefined,
    databricksCompute: undefined,
};
